
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Calendar Date Select Test Cases</title>
  <script src="../prototype.js" type="text/javascript"></script>
  <script src="../unittest.js" type="text/javascript"></script>
  <!-- other JavaScript includes -->
  <script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
  
  <link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
  <link rel="stylesheet" href="../test.css" type="text/css" />
</head>
<body>

<!-- Log output -->
<div id="testlog"> </div>

<!-- here go any elements you do the testing on -->
<input type="text" id="cds_test" />

<!-- Tests -->
<script type="text/javascript" language="javascript">
// <![CDATA[
  new Test.Unit.Runner({
    setup: function() { with(this){
      $("cds_test").value="";
      $("cds_test").disabled = false;
      $("cds_test").readOnly = false;

    }},
    testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
      $A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
        $("cds_test").value=d;
        cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
        assertEqual(true, cds.use_time);
        cds.close();
      })
      
      $("cds_test").value="January 2, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      assertEqual(false, cds.use_time);
      cds.close();      
    }},
    testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      today_now = $$(".cds_buttons a[href=#]");
      today_now[0].onclick();
      assertEqual(false, cds.use_time, "when clicking today link");
      
      today_now[1].onclick();
      assertEqual(true, cds.use_time, "should have been true when clicking now link");
      cds.close();
    }},
    test_updateSelectedDate: function() { with(this){
      $("cds_test").value = "January 1, 2007"
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});

      cds.use_time=true;
      cds.updateSelectedDate({hour: ""})
      assertEqual(false, cds.use_time, "when setting hour to ''");
      
      cds.use_time=true;
      cds.updateSelectedDate({minute: ""})
      assertEqual(false, cds.use_time, "when setting minute to ''");
      
      cds.use_time=false;
      cds.updateSelectedDate({hour: 0})
      assertEqual(true, cds.use_time, "when setting hour to 0");
      
      cds.use_time=false;
      cds.updateSelectedDate({minute: 0})
      assertEqual(true, cds.use_time, "when setting minute to 0");
      
      cds.close();
    }},
    test_navYear_navMonth: function() { with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      cds.navYear(1870);
      assertEqual(2007, cds.selected_date.getFullYear());
      assertEqual(1870, cds.date.getFullYear());
      
      cds.navMonth(5);
      assertEqual(0, cds.selected_date.getMonth());
      assertEqual(5, cds.date.getMonth())
      cds.close();
    }},
    test_disabledElement_cantUpdate: function() {with(this){
      $("cds_test").value = "May 10, 2007";
      $("cds_test").disabled = true;
      cds = new CalendarDateSelect($("cds_test"));
      
      runTest = function() {
        cds.updateSelectedDate({day: 1, month:0, year: 2007});
        assertEqual(10, cds.selected_date.getDate())
      }
      runTest();
      $("cds_test").disabled = false;
      $("cds_test").readOnly = true;
      runTest();
      
      $("cds_test").readOnly = false;
      cds.close();
    }},
    test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
      $("cds_test").value = "May 10, 2007";
      $("cds_test").readOnly = true;
      cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
      
      cds.updateSelectedDate({day: 1, month:0, year: 2007});
      assertEqual(1, cds.selected_date.getDate())
      
      $("cds_test").readOnly = false;
      cds.close();
    }},
    test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
      $("cds_test").value = "May 10, 2007 5:00 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      assertEqual(false, cds.use_time, "When parsing time");
      cds.today(); // this will close the control
      assertEqual(false, cds.use_time, "When calling today");
      
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
      assertEqual(false, cds.use_time, "When setting hour/minute");
    }},
    test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
      $("cds_test").value = "May 10, 2007 5:00 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      assertEqual(false, cds.use_time, "When parsing time");
      cds.setUseTime(true); // this will close the control
      assertEqual(false, cds.use_time, "After calling setUseTime(true)");
      cds.close();
    }},
    test_setMinute_notOnInterval_usesFloor: function() {with(this){
      $("cds_test").value = "May 10, 2007 5:25 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      cds.updateSelectedDate({hour: 1, minute: 4});
      assertEqual(0, cds.selected_date.getMinutes());
      assertEqual(1, cds.selected_date.getHours());
      
      cds.close();
    }},
    // this checks for a safari 2 bug where safari parses "" as a date back in 1969
    test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
      $("cds_test").value = " ";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
      assertEqual(new Date().getFullYear(), cds.date.getFullYear());
      assertEqual(false, cds.selection_made)
      cds.close();
    }},
    test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
      $("cds_test").value = "December 1, 2007 ";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      assertEqual(true, cds.use_time)
      cds.close();
    }}
    
  });
// ]]>
</script>
</body>
</html>